from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.utils import Bunch
import numpy as np
"""
随机森林模型测试
"""
# 加载Iris数据集
iris: Bunch = load_iris()
X = iris.data
y = iris.target

# 创建随机森林分类器实例
rf_classifier = RandomForestClassifier(n_estimators=100)  # n_estimators是树的数量

# 训练模型
rf_classifier.fit(X, y)
print(iris.data)
print(iris.target)
# 预测新数据
X_new = [[3.1, 3.2, 3.3, 2.4]]  # 示例数据
y_pred = rf_classifier.predict(X_new)

print(y_pred)  # 输出预测结果